<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ page import="com.c0nflict.server.*, com.mysql.jdbc.Statement, com.mysql.jdbc.ResultSet" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="style.css"></link>
<link rel="stylesheet" type="text/css" href="tabber.css"></link>
<script type="text/javascript" src="tabber-minimized.js"></script>
<title>c0nflict - Leaderboard</title>
<style>
th { height: 50px; }
tr {height : 30px; }
th.sm { height: 48px; }
tr.sm { height: 28px; }
.tabber{display:none;}
</style>
</head>
<body>
<div id="header" style="height: 33px;"></div><br/>
<%
Database db = new Database();

int elo = 0;
String imgCode = "";
%>
<table valign="top" cellspacing="20">
<tr>
<td colspan="0" align="center"><font size="5" color="white" face="verdana"><b>Leaderboard</b></font></td>
</tr>
<tr>
<td valign="top">
<div class="tabber" id="tab1">
<% 
if (db == null)
	out.println("Unable to connect to database!");
else {
	Statement stmt = (Statement)db.getConnection().createStatement();
	String query = 
		"select d.user_id Id, d.username Name, d.user_email Email, u.admin_level Admin,  eloch, u.elo ELO, p.games Games " +
		"from jforum_users d, dq_user u, " +
		"(select user_id, count(game_id) as games,-1*sum(elo_change) as eloch from dq_game_stats_players " +
				" where death_time > date_add(curdate(), interval -1 day) group by 1) p " +
		"where d.user_id<> 4178 and  (u.admin_level < 2 or u.admin_level is null) and u.user_id = d.user_id and p.user_id = u.user_id and p.games > 0 order by eloch desc limit 25"; 
	ResultSet rs = (ResultSet)stmt.executeQuery(query);
%>
<div class="tabbertab" title="Today">
<table width="20%" align="center">
<tr><td align="center"><font size="3" color="white" face="verdana"><b>Today</b></font></td></tr>
</table>
<table align="center" border=0 cellpadding="4" cellspacing="0">
<tr class="sm" bgcolor="#111">
	<th width="60px">Rank</th>
	<th width="300px">Name</th>
	<th width="60px">Rating Increase</th>
	<th width="60px">Rating</th>
	<th width="100px">Games (last 24 hrs)</th>
</tr>
	<% while (rs.next()) {
		elo = rs.getInt("ELO");
		imgCode = "src=\"" + Rank.getRankImageSmall(elo) + "\" title=\"" + Rank.getRankName(elo) + "\"";
		%><tr class="sm" <% if (rs.getRow() % 2 == 0) { %> bgcolor="#222" <% } else { %> bgcolor="#000" <% } %> >
	<td align="center"><%= rs.getRow() %></td>
	<td><img height=28 width=45 <%= imgCode %>>&nbsp;<%= rs.getString("Name") %></td>
	<td align="center"><%= rs.getInt("eloch") %></td>
	<td align="center"><%= rs.getInt("ELO") %></td>
	<td align="center"><%= rs.getInt("Games") %></td>
</tr>
	<% } %>
</table>
</div>
<% } %>
<%
if (db == null)
	out.println("Unable to connect to database!");
else {
	Statement stmt = (Statement)db.getConnection().createStatement();
	String query = 
		"select d.user_id Id, d.username Name, d.user_email Email, u.admin_level Admin, eloch, u.elo ELO, p.games Games " +
		"from jforum_users d, dq_user u, " +
		"(select user_id, count(game_id) games, sum(-1*elo_change) as eloch  from dq_game_stats_players " +
				" where death_time > date_add(curdate(), interval -7 day) group by 1) p " +
		"where d.user_id<> 4178 and (u.admin_level < 2 or u.admin_level is null) and u.user_id = d.user_id and p.user_id = u.user_id and p.games > 4 order by eloch desc limit 25"; 
	ResultSet rs = (ResultSet)stmt.executeQuery(query);
%>
<div class="tabbertab" title="Week">
<table width="20%" align="center">
<tr><td align="center"><font size="3" color="white" face="verdana"><b>Week</b></font></td></tr>
</table>
<table align="center" border=0 cellpadding="4" cellspacing="0">
<tr class="sm" bgcolor="#111">
	<th width="60px">Rank</th>
	<th width="300px">Name</th>
	<th width="60px">Rating Increase</th>
	<th width="60px">Rating</th>
	<th width="100px">Games<br/>(last 7 days)</th>
</tr>
	<% while (rs.next()) {
		elo = rs.getInt("ELO");
		imgCode = "src=\"" + Rank.getRankImageSmall(elo) + "\" title=\"" + Rank.getRankName(elo) + "\"";
		%>
<tr class="sm" <% if (rs.getRow() % 2 == 0) { %> bgcolor="#222" <% } else { %> bgcolor="#000" <% } %> >
	<td align="center"><%= rs.getRow() %></td>
	<td><img height=28 width=45 <%= imgCode %>>&nbsp;<%= rs.getString("Name") %></td>
	<td align="center"><%= rs.getInt("eloch") %></td>
	<td align="center"><%= rs.getInt("ELO") %></td>
	<td align="center"><%= rs.getInt("Games") %></td>
</tr>
	<% } %>
</table>
</div>
<% } %>
</div>
</td>
<td>
<%
if (db == null)
	out.println("Unable to connect to database!");
else {
	Statement stmt = (Statement)db.getConnection().createStatement();
	String query = 
		"select d.user_id Id, d.username Name, d.user_email Email, u.admin_level Admin, eloch, u.elo ELO, p.games Games " +
		"from jforum_users d, dq_user u, " +
		"(select user_id, count(game_id) games,-1*sum(elo_change)  eloch from dq_game_stats_players " +
		" where death_time > date_add(curdate(), interval -28 day) group by 1) p, " +
		"(select user_id, count(game_id) games from dq_game_stats_players " +
		" where death_time > date_add(curdate(), interval -5 day) group by 1) p2 " +
		"where d.user_id<> 4178 and  (u.admin_level < 2 or u.admin_level is null) and u.user_id = d.user_id and p.user_id = u.user_id and p.games > 10 and p2.user_id=p.user_id and p2.games>2 order by u.elo desc limit 25"; 
	ResultSet rs = (ResultSet)stmt.executeQuery(query);
%>
<table width="20%" align="center">
<tr><td align="center"><font size="3" color="white" face="verdana"><b>All Time</b></font></td></tr>
</table>
<table align="center" border=0 cellpadding="4" cellspacing="0">
<tr bgcolor="#111">
	<th width="60px">Rank</th>
	<th width="300px">Name</th>
	<th width="60px">Rating Change</th>
	<th width="60px">Rating</th>
	<th width="100px">Games <br/>(last 4 wks)</th>
</tr>
	<% while (rs.next()) {
		elo = rs.getInt("ELO");
		imgCode = "src=\"" + Rank.getRankImageSmall(elo) + "\" title=\"" + Rank.getRankName(elo) + "\"";
		%>
<tr <% if (rs.getRow() % 2 == 0) { %> bgcolor="#222" <% } else { %> bgcolor="#000" <% } %> >
	<td align="center"><%= rs.getRow() %></td>
	<td><img <%= imgCode %>>&nbsp;<%= rs.getString("Name") %></td>
	<td align="center"><%= rs.getInt("eloch") %></td>
	<td align="center"><%= rs.getInt("ELO") %></td>
	<td align="center"><%= rs.getInt("Games") %></td>
</tr>
	<% } %>
</table>
<% } %>
</td>
</tr>
</table>

</body>
</html>
